package com.xnsy.jishexiangmu.service.luntan.impl;

import com.xnsy.jishexiangmu.mapper.LunTanMapper;
import com.xnsy.jishexiangmu.pojo.LunTan;
import com.xnsy.jishexiangmu.pojo.PingLun;
import com.xnsy.jishexiangmu.service.luntan.LunTanServer;
import com.xnsy.jishexiangmu.uitl.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LunTanServiceImpl implements LunTanServer {
    @Autowired
    private LunTanMapper lunTanMapper;

    @Override
    public List<LunTan> get() {
        return lunTanMapper.get();
    }

    @Override
    public void addDianZan(Integer id) {
        lunTanMapper.addDianZan(id);
    }

    @Override
    public void addMessage(LunTan lunTan) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        lunTan.setUsername(username);
        lunTanMapper.addMessage(lunTan);
    }

    @Override
    public LunTan getOne(Integer id) {
        return lunTanMapper.getOne(id);
    }

    @Override
    public List<PingLun> getPingLun(Integer pid) {
        return lunTanMapper.getPingLun(pid);
    }

    @Override
    public void addPingLun(PingLun pingLun) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        pingLun.setUsername(username);
        lunTanMapper.addPinglun(pingLun);
    }
}
